const log = require('./log-util')
const fs = require('fs')

const conf = "{\n" +
    "  \"dnspodId\": \"123456\",\n" +
    "  \"dnspodSecretKey\": \"**************\",\n" +
    "  \"domains\": [\n" +
    "    [\"welcome.com\", \"@\", \"blog\"]\n" +
    "  ]\n" +
    "}"

const confFound = () => {
    if (fs.existsSync('./conf/conf.json')) {
        return require('./conf/conf.json')
    } else if (fs.existsSync(log.basicPath + 'conf.json')) {
        return require(log.basicPath + 'conf.json')
    } else {
        fs.writeFileSync(log.basicPath + "conf.json", conf, 'utf-8')
        const message = `could not find conf.json...\n Already generate the conf.json in ${log.basicPath}, please check and change it!`
        log.error(`conf-found`, message)
        throw new Error(message)
    }
}

module.exports = confFound()